﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Somnus.Core;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Contacts;

namespace Somnus.Objects.GameObjects.LevelObjects
{
    class WindGenerator : Platform
    {
        public int windDuration;
        public int delayBetweenWinds;
        private int windTimer;

        public WindGenerator(DreamWorld world, String name, Texture2D texture, Nullable<Rectangle> sourceRectangle, BodyType bodyType, float x, float y, float width, float height)
            : base(world, name, texture, sourceRectangle, bodyType, x, y, width, height)
        {
            windDuration = 90;
            delayBetweenWinds = 120;
            windTimer = 0;
        }

        public override void update(GameTime gameTime)
        {
            if (windTimer >= delayBetweenWinds + windDuration)
            {
                float windWidth = 100;
                float windHeight = 400;
                float posX = this.x + (float)(Math.Sin(MathHelper.ToRadians(this.Rotation)) * ((windHeight / 2) + 40));
                float posY = this.y + -(float)(Math.Cos(MathHelper.ToRadians(this.Rotation)) * ((windHeight / 2) + 40));
                Wind wind = new Wind(DreamWorld.getWorld(), "WIND", null, null, BodyType.Static, posX, posY, windWidth, windHeight, windDuration);
                wind.Rotation = this.Rotation;

                windTimer = 0;
            }
            else
            {
                windTimer++;
            }

            base.update(gameTime);
        }

        protected override void HandleIsColliding(Fixture thisFixture, Fixture otherFixture)
        {
            
            base.HandleIsColliding(thisFixture, otherFixture);
        }
    }
}
